﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using Microsoft.Ted.Wacel.TestConsole.Properties;
using Microsoft.Ted.Wacel.TableStorage;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Microsoft.Ted.Wacel.TestConsole.PerformanceTests
{
    public class CloudTableStoragePerfTester
    {
        public static int InsertOrReplace(Stopwatch watch)
        {
            int count = 1000;
            CloudTableStorage<Customer> storage = new CloudTableStorage<Customer>("ID", Settings.Default.StorageConnectionString, "customers", false);
            storage.Clear();
            watch.Restart();
            for (int i = 0; i < count; i++)
                storage.InsertOrReplace(new Customer { ID = i, Name = "This is a customer.", Value = 123.456, Time = DateTime.UtcNow, Company = "A Company" });
            watch.Stop();
            return count;
        }

        public static int InsertOrReplaceWithBatch(Stopwatch watch)
        {
            int count = 1000;
            CloudTableStorage<Customer> storage = new CloudTableStorage<Customer>("Company", "ID", Settings.Default.StorageConnectionString, "customers", false);
            storage.Clear();
            watch.Restart();
            for (int i = 0; i < 10; i++)
            {
                List<Customer> customers = new List<Customer>();
                for (int j = 0; j < 100; j++ )
                    customers.Add(new Customer { ID = j, Name = "This is a customer.", Value = 123.456, Time = DateTime.UtcNow, Company = "Company" + i.ToString()});
                storage.BulkInsertOrReplace(customers);
            }
            watch.Stop();
            return count;
        }

    }
}
